# -*- coding: utf-8 -*-
from datetime import timedelta
# from airflow.operators.bash_operator import BashOperator
from spmi_hedge_hi.dwd.dwd_spmi_union_bill_hi import spmi_dwd__dwd_spmi_union_bill_hi
from spmi_hedge_hi.dwd.dwd_spmi_piece_bill_hi import spmi_dwd__dwd_spmi_piece_bill_hi
from spmi_hedge_hi.dwd.dwd_spmi_apack_bill_hi import spmi_dwd__dwd_spmi_apack_bill_hi
from spmi_hedge_hi.dwd.dwd_spmi_operation_bill_hi import spmi_dwd__dwd_spmi_operation_bill_hi
from spmi_hedge_hi.dwd.dwd_spmi_composite_bill_hi import spmi_dwd__dwd_spmi_composite_bill_hi
from spmi_hedge_hi.dwd.dwd_spmn_tran_oper_bill_hi import spmi_dwd__dwd_spmn_tran_oper_bill_hi

from airflow.exceptions import AirflowSkipException
from utils.operators.latest_only_bash_operator import BashOperator
import pendulum

cst = pendulum.timezone('Asia/Shanghai')

class SpmiQualityBashOperator(BashOperator):
    def pre_execute(self, context):
        day = cst.convert(context['ti'].execution_date) + timedelta(days=1)

        days_of_hours = ['07']

        if day.strftime('%H') not in days_of_hours:
            print(f'{day.strftime("%H")} not in {days_of_hours}, should skip')
            raise AirflowSkipException()
        else:
            print(f'{day.strftime("%H")} in {days_of_hours}, run now')
            super().pre_execute(context)

spmi_dwd__dwd_spmi_quality_monitor_dt = SpmiQualityBashOperator(
    task_id='spmi_dwd__dwd_spmi_quality_monitor_dt',
    email=['jarl.huang@jtexpress.com','yl_bigdata@yl-scm.com'],
    bash_command="spmi_hedge_hi/dwd/dwd_spmi_quality_monitor_dt/execute.sh",
    pool='unlimited_pool',
    # yarn_queue='pyspark',
    priority_weight=0,
)

spmi_dwd__dwd_spmi_quality_monitor_dt << [
    spmi_dwd__dwd_spmi_union_bill_hi,
    spmi_dwd__dwd_spmi_piece_bill_hi,
    spmi_dwd__dwd_spmi_apack_bill_hi,
    spmi_dwd__dwd_spmi_operation_bill_hi,
    spmi_dwd__dwd_spmn_tran_oper_bill_hi,
    spmi_dwd__dwd_spmi_composite_bill_hi
]